<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <link rel="stylesheet" type="text/css" media="screen"
          href="../static/css/bootstrap.min.css">
    <script src="../static/js/axios.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            min-height: 100vh;
            background: linear-gradient(135deg, #009ffd, #0066ff);
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        .login-container {
            background: white;
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
            width: 350px;
            text-align: center;
        }

        .login-title {
            font-size: 28px;
            color: #333;
            margin-bottom: 30px;
        }

        .input-group {
            width: 100%;
            margin: 15px 0;
        }

        .input-group input, .input-group select {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            outline: none;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .input-group input:focus, .input-group select:focus {
            border-color: #009ffd;
            box-shadow: 0 0 5px rgba(0, 158, 255, 0.3);
        }

        .login-btn {
            background: linear-gradient(45deg, #009ffd, #0066ff);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 25px;
        }

        .login-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .links {
            margin-top: 20px;
            font-size: 14px;
            color: #666;
        }

        .links a {
            color: #0066ff;
            text-decoration: none;
            margin: 0 10px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2 class="login-title">欢迎登录</h2>
    <form>
        <div class="input-group">
            <input id="username" type="text" placeholder="用户名" required>
        </div>
        <div class="input-group">
            <select id="type" required>
                <option value="">请选择类型</option>
                <option value="老师">老师</option>
                <option value="学生">学生</option>
            </select>
        </div>
        <div class="input-group">
            <input id="password" type="password" placeholder="密码" required>
        </div>
        <button id="dl" class="login-btn">登录</button>
        <div class="links">
            <a href="#">忘记密码？</a>
            <button type="button" onclick="location.href='/index/register.html'">注册</button>
        </div>
    </form>
</div>
</body>

<script>
    document.getElementById("dl").onclick = function (event) {
        event.preventDefault(); // 阻止表单默认提交行为
        console.log("登录按钮被点击");

        const username = document.getElementById("username").value;
        const password = document.getElementById("password").value;
        const type = document.getElementById("type").value;

        console.log("用户名:", username);
        console.log("密码:", password);
        console.log("类型:", type);

        // 确保字段不为空
        if (!username || !password || !type) {
            alert('请填写所有字段');
            return;
        }

        const url="http://localhost:8080/student/login";
        const data={
            username:username,
            password:password,
            type:type
        }
        axios
            .post(url,data)
            .then(function (response) {
                console.log(response);
                if (response.data==="ok"){
                    //登录成功,跳转到
                    window.location.href="./home.html";
                }else {
                    //登录失败
                    document.getElementById("error-message").innerHTML=response.data.message;
                }
            })
    }
</script>
</html>
